﻿package plugin.chatflash.component
{
    import __AS3__.vec.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;
    import morn.core.components.*;
    import pluginfw.*;

    public class PrivateChatPanel extends Sprite
    {
        private var mText1:TextField;
        private var mText2:TextField;
        private var mBtn:Button;
        private var mfaceBtn:ChatBtn;
        private var mNameBox:Sprite;
        private var mPanel:DisplayObject;
        private var mTFList:Vector.<TextField>;
        private var mRoleList:Vector.<Object>;
        private var mSelectedRole:Object;
        private var mFilter:DropShadowFilter;
        private const ROLE_LIMIT:int = 4;

        public function PrivateChatPanel()
        {
            this.mFilter = new DropShadowFilter(0, 0, 0, 0.8, 2, 2, 10, 1);
            this.mTFList = new Vector.<TextField>;
            this.mRoleList = new Vector.<Object>;
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            this.mNameBox = new Sprite();
            this.mNameBox.y = -88;
            this.mNameBox.visible = false;
            addChild(this.mNameBox);
            this.mPanel = new BitmapScale9Grid(new Bitmap(App.asset.getBitmapData("png.common.s9_tish")), 3, 50, 3, 50);
            this.mPanel.width = 126;
            this.mPanel.height = 80;
            this.mNameBox.addChild(this.mPanel);
            this.mText1 = new TextField();
            this.mText1.textColor = 11680494;
            this.mText1.filters = [this.mFilter];
            this.mText1.y = 8;
            addChild(this.mText1);
            this.mText2 = new TextField();
            this.mText2.textColor = 11680494;
            this.mText2.text = "说:";
            this.mText2.x = 127;
            this.mText2.y = 8;
            this.mText2.filters = [this.mFilter];
            this.mText2.mouseEnabled = false;
            addChild(this.mText2);
            this.mBtn = new Button("png.common.btn_cha");
            this.mBtn.x = 107;
            this.mBtn.y = 6;
            addChild(this.mBtn);
            this.listener();
            return;
        }// end function

        private function listener() : void
        {
            this.mNameBox.addEventListener(MouseEvent.CLICK, this.selectRoleHandler, false, 0, true);
            this.mBtn.addEventListener(MouseEvent.CLICK, this.showRoleListHandler, false, 0, true);
            return;
        }// end function

        private function selectRoleHandler(event:MouseEvent) : void
        {
            var _loc_2:Object = null;
            if (event.target is TextField)
            {
                _loc_2 = this.mRoleList[this.mTFList.indexOf(TextField(event.target))];
                if (this.mSelectedRole != _loc_2)
                {
                    this.mSelectedRole = _loc_2;
                    this.updateSelectedRole();
                }
                this.mBtn.selected = false;
                this.mNameBox.visible = false;
            }
            return;
        }// end function

        private function updateSelectedRole() : void
        {
            this.mText1.htmlText = StringUtil.substitute("对\t<u><font color=\'#{0}\'>{1}</font></u>", MColor.S_PINK, this.mSelectedRole.name);
            return;
        }// end function

        public function addRole(param1:Object) : void
        {
            var _loc_2:int = 0;
            while (_loc_2 < this.mRoleList.length)
            {
                
                if (this.mRoleList[_loc_2].rid == param1.rid)
                {
                    return;
                }
                _loc_2++;
            }
            this.mRoleList.push(param1);
            if (this.mRoleList.length > this.ROLE_LIMIT)
            {
                this.mRoleList.shift();
            }
            this.updateRoleList();
            this.mSelectedRole = param1;
            this.updateSelectedRole();
            return;
        }// end function

        private function updateRoleList() : void
        {
            var _loc_2:TextField = null;
            var _loc_3:TextField = null;
            while (this.mTFList.length > 0)
            {
                
                _loc_2 = this.mTFList.shift();
                if (_loc_2.parent)
                {
                    _loc_2.parent.removeChild(_loc_2);
                }
                _loc_2 = null;
            }
            var _loc_1:int = 0;
            while (_loc_1 < this.mRoleList.length)
            {
                
                _loc_3 = new TextField();
                _loc_3.textColor = 11680494;
                _loc_3.text = String(this.mRoleList[_loc_1].name);
                _loc_3.x = 5;
                _loc_3.y = 4 + 19 * _loc_1;
                _loc_3.filters = [this.mFilter];
                this.mNameBox.addChild(_loc_3);
                this.mTFList.push(_loc_3);
                _loc_1++;
            }
            return;
        }// end function

        private function showRoleListHandler(event:MouseEvent) : void
        {
            this.mBtn.selected = !this.mBtn.selected;
            this.mNameBox.visible = this.mBtn.selected;
            return;
        }// end function

        public function get selectedRole() : Object
        {
            return this.mSelectedRole;
        }// end function

    }
}
